package noticeboard;

import java.util.List;

import com.andro.chansung.R;

import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NoticeAdapter extends BaseAdapter {

	private Context context;
	
	private LayoutInflater inflater;
	private ViewHolder viewHolder;
	private List<Notice> notices;
	
	private class ViewHolder {
		public ImageView imageView = null;
		public TextView  titleTv   = null;
		public TextView  dateTv    = null;
	}
	
	public NoticeAdapter(Context context, List<Notice> notices) {
		this.context  = context;
		this.inflater = LayoutInflater.from(context);
		this.notices  = notices;
	}
	
	public int getCount() {
		return notices.size();
	}

	public Notice getItem(int position) {
		return notices.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		
		if( view == null ) {
			viewHolder = new ViewHolder();
			view = inflater.inflate(R.layout.notice_board_list_view_cell_layout, null);
			viewHolder.imageView = (ImageView)view.findViewById(R.id.notice_board_list_view_cell_img);
			viewHolder.titleTv   = (TextView)view.findViewById(R.id.notice_board_list_view_cell_title_tv);
			viewHolder.dateTv    = (TextView)view.findViewById(R.id.notice_board_list_view_cell_date_tv);
			
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder)view.getTag();
		}
		
		if( position == 0 ) {
			viewHolder.imageView.setImageResource(R.drawable.top_most);
		} else if ( position == 1 || position == 2 ) {
			viewHolder.imageView.setImageResource(R.drawable.somewhat_new);
		} else {
			viewHolder.imageView.setImageResource(R.drawable.normal);
		}
		
		Notice notice = getItem(position);
		viewHolder.titleTv.setText(notice.getTitle());
		viewHolder.dateTv.setText(notice.getDate());
		return view;
	}
}